package com.doctorliang.cheng.shopping.community.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.doctorliang.cheng.shopping.community.fragment.HotPostFragment;
import com.doctorliang.cheng.shopping.community.fragment.NewPostFragment;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by YBH on 2017/12/15.
 */

public class CommunityViewPagerAdapter extends FragmentPagerAdapter{
    //tablayout标题
    private String [] titles = new String[]{"热帖","新帖"};
    private List<Fragment> fragmentList;

    @Override
    public CharSequence getPageTitle(int position) {
        return titles[position];
    }

    public CommunityViewPagerAdapter(FragmentManager fm) {
        super(fm);
        intiFragments();
    }

    private void intiFragments() {
        fragmentList = new ArrayList<>();
        HotPostFragment hotPostFragment = new HotPostFragment();
        NewPostFragment newPostFragment = new NewPostFragment();

        fragmentList.add(hotPostFragment);
        fragmentList.add(newPostFragment);
    }

    @Override
    public Fragment getItem(int position) {
        return fragmentList.get(position);
    }

    @Override
    public int getCount() {
        return fragmentList==null?0:fragmentList.size();
    }
//
//    @Override
//    public Object instantiateItem(ViewGroup container, int position) {
//        return super.instantiateItem(container, position);
//    }

//    @Override
//    public boolean isViewFromObject(View view, Object object) {
//        return view==object;
//    }
//
//    @Override
//    public void destroyItem(ViewGroup container, int position, Object object) {
////        container.removeView((View) object);
//    }

}
